<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>商品信息列表</title>
    <link rel="stylesheet" href="layui/css/layui.css" class="css">
    <style>
        .checkGoodsListPop {
            margin: 5px 20px;
            text-align: center;
        }

        .checkGoodsListPop th {
            text-align: center;
        }
        .checkGoodsListPop input[type='radio']{
            display: block;
        }
    </style>
</head>

<body>
    <div class="checkGoodsListPop">
        <form class="layui-form">
            <table class="layui-table">
                <colgroup>
                    <col width="120">
                    <col width="252">
                    <col width="450">
                    <col>
                </colgroup>
                <thead>
                    <tr>
                        <th>选择商品</th>
                        <th>简称</th>
                        <th>商品名称</th>
                    </tr>
                </thead>
                <tbody class="goodsLists">
                </tbody>
            </table>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="goodIdCheck" type="button">立即提交</button>
                </div>
            </div>
        </form>
    </div>
    <script src="js/jquery.min.js"></script>
    <script src="js/jquery.cookie.js"></script>
    <script src="layui/layui.js"></script>
    <script src="js/dataRequest.js"></script>
    <script>
        var mid = $.cookie('id');
        var pageNum = 1;
        layui.use(['layer', 'form'], function (args) {
            var layer = layui.layer,
                form = layui.form;
            // 商品列表
            $.ajax({
                type: "GET",
                url: BASE_URL + MAP_URL +
                    "goods/list/" + pageNum + '/10/?merchantsId=' + mid,
                dataType: 'json',
                // contentType: "application/json;charset=utf-8",
                // data: JdateJson,
                success: function (data) {
                    console.log("商品列表", data.data)
                    if (!data.data.list) {
                        layer.open({
                            title: "提示",
                            content: "您需要添加商品"
                        });
                        return;
                    }
                    var str = "";
                    for (var i = 0; i < data.data.list.length; i++) {
                        str += '<tr>';
                        str += '<td><input type="radio" name="goods" value="' +
                            data.data.list[i].id + '"></td>';
                        str += '<td>' + data.data.list[i].goodsInfo + '</td>';
                        str += '<td>';
                        str += '<p class="goodsName">';
                        str += '' + data.data.list[i].goodsName + '';
                        str += '</p>';
                        str += '</td>';
                        str += '</tr>';
                    }
                    $(".goodsLists").append(str);
                    $("input[type='radio']").on("click", function () {
                        var goodId = $(this).val();
                        console.log("拿到的当前数据的id", goodId);
                        form.on('submit(goodIdCheck)', function (data) {
                            parent.GetValue(goodId);
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
                        });
                    });
                }
            });

        });
    </script>
</body>

</html>